﻿using FreeSql;
using IMES.Common.Domain.DurianModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace Durian.API.Application.Commands.Assembly
{
    public class OrderAssemblySearchHandler : IRequestHandler<OrderAssemblySearchCommand, Result>
    {
        private readonly IBaseRepositorys<Assemblies> assembliesRepository;

        public OrderAssemblySearchHandler(IBaseRepositorys<Assemblies> assembliesRepository)
        {
            this.assembliesRepository = assembliesRepository;
        }

        /// <summary>
        /// 打印装配工单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(OrderAssemblySearchCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CodeEnum.search };
            var list = assembliesRepository.GetAll().Where(x => x.AssemblyId == request.AssemblyId).FirstOrDefault();
            result.Data = list;
            result.Messege = "装配工单查询成功";
            return result;
        }
    }
}
